<?php

namespace Member\Controller;

/**
 * 外观管理 控制器
 *
 * @since 1.0 <2017-3-27> SoChishun <14507247@qq.com> Added.
 */
class CustomTheme extends AppbaseController {

    public function editView($title) {
        $where = array('title' => $title);
        $mSkin = new \XWAM\Model\CustomThemeModel();
        $data = $mSkin->where($where)->find();
        if (!$data) {
            $mSkin->add($where);
            $data = $mSkin->where($where)->find();
        }
        if (!$data) {
            exit('数据库错误!'.$mSkin->getDbError());
        }
        $this->assign('data', $data);
        $this->assign('tabs', $this->getTabs());
        $this->display();
    }

    public function edit() {
        $this->editView('base');
    }

    public function head() {
        $this->editView('head');
    }

    public function foot() {
        $this->editView('foot');
    }

    public function editSave() {
        $mSkin = new \XWAM\Model\CustomThemeModel();
        $result = $mSkin->saveSkin();
        $this->dialogJump($result['status'], $result['info']);
    }

    // 2017-3-23
    protected function getTabs($name = '') {
        if (!$name) {
            $name = ACTION_NAME;
        }
        $data = array(
            'edit' => array('title' => '基本样式', 'url' => 'edit', 'active' => ''),
            'head' => array('title' => '头部样式', 'url' => 'head', 'active' => ''),
            'foot' => array('title' => '底部样式', 'url' => 'foot', 'active' => ''),
            //'images' => array('title' => '素材管理', 'url' => 'images', 'active' => ''),
        );
        if (array_key_exists($name, $data)) {
            $data[$name]['active'] = 'active';
        }
        return $data;
    }

}
